using System;
using Microsoft.Practices.ObjectBuilder2;
using Microsoft.Practices.Unity;

namespace UniAspect.ContainerOverride
{
    [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    public sealed class ContainerOverrideAttribute : DependencyResolutionAttribute
    {
        public string Name { get; set; }

        public string ContainerName { get; set; }

        public ContainerOverrideAttribute() : this(null)
        {
        }

        public ContainerOverrideAttribute(string containerName) : this(null, containerName)
        {
        }

        public ContainerOverrideAttribute(string name, string containerName)
        {
            Name = name;
            ContainerName = containerName;
        }

        public override IDependencyResolverPolicy CreateResolver(Type typeToResolve)
        {
            return new OverriddenDependencyResolverPolicy(typeToResolve, Name, ContainerName);
        }
    }
}